<?php /* SVN: $Id: index.ctp 2901 2010-09-02 11:49:34Z sakthivel_135at10 $ */ ?>
<div class="js-response">
	<div class="my-projects-block">
		<h3><?php echo __l('My Projects'); ?></h3>
		<h3><?php echo __l('Overview'); ?></h3>
		<?php echo $this->element('user-stats', array('config' => 'sec')); ?>
		<div class="content-info clearfix">
			<p><?php
			if(Configure::read('Project.is_enable_threshold_limit') ):
				echo __l('Funds will be captured and released only when total pledges reach reserve amount or goal amount.'); 
			else:
				echo __l('When goal amount has been reached then funds can start to be released.'); 
			endif;
			?></p>
		</div>
		<div class="clearfix">
		<ul class="filter-list-block clearfix">
    	<?php $class=(empty($this->request->params['named']['status']) && !empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects')?'active':'';?>
    		<li  class= "js-pagination <?php echo $class; ?>"><span class="import-block" title="<?php echo __l('All'); ?>"><?php echo $this->Html->link($this->Html->cInt($count,false).'<span>' .__l('All'). '</span>', array('controller'=>'projects','action'=>'index','type' => 'myprojects'), array('escape' => false));?></span> </li>
		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status'])&& $this->request->params['named']['status'] == 'pending')?'active':'';?>
            <li  class= "js-pagination <?php echo $class; ?>"><span class="gmail-block" title="<?php echo __l('Pending'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::Pending],false).'<span>' .__l('Pending'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'pending'), array('escape' => false));?></span> </li>
		<?php
		if(Configure::read('Project.is_enable_idea')):
		  $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'idea')?'active':'';?>
            <li  class= "js-pagination <?php echo $class; ?>"><span class="yahoo-block" title="<?php echo __l('Open for Voting'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::OpenForIdea],false).'<span>' .__l('Open for Voting'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'idea'), array('escape' => false));?></span> </li>
		<?php endif; ?>
		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'open_for_funding')?'active':'';?>
            <li  class= "js-pagination <?php echo $class; ?>"><span class="lightblue-block" title="<?php echo __l('Open for Funding'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::OpenForFunding],false).'<span>' .__l('Open for Funding'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'open_for_funding'), array('escape' => false));?></span> </li>
        <?php
		if(Configure::read('Project.is_enable_threshold_limit')):
			$class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'reserve_amount_reached')?'active':'';?>
            <li  class= "js-pagination <?php echo $class; ?>"><span class="bluedark" title="<?php echo __l('Reserve Amount Reached'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::ReserveAmountReached],false).'<span>' .__l('Reserve Amount Reached'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'reserve_amount_reached'), array('escape' => false));?></span> </li>
		<?php endif; ?>
        <?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'goal')?'active':'';?>
            <li  class= "js-pagination <?php echo $class; ?>"><span class="lightpink-block" title="<?php echo __l('Goal Reached'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::GoalReached],false).'<span>' .__l('Goal Reached'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'goal'), array('escape' => false));?></span> </li>
        	<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'closed')?'active':'';?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="green-block" title="<?php echo __l('Funding Closed and Paid to Project Owner'); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::FundingClosed],false).'<span>' .__l('Funding Closed and Paid to Project Owner'). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'closed'), array('escape' => false));?></span> </li>

        <?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'cancelled')?'active':'';?>
         <li  class= "js-pagination <?php echo $class; ?>"><span class="pink-block" title="<?php if($is_wallet_enabled){ $current_title = __l('Refunded due to Canceled');} else{$current_title = __l('Voided due to Canceled');}echo $current_title;; ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::ProjectCancelled],false).'<span>' .$current_title. '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'cancelled'), array('escape' => false));?></span> </li>
        
	    <?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'expired')?'active':'';   if($is_wallet_enabled){ $current_title = 'Refunded due to Expired';} else{$current_title = 'Voided due to Expired';}?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="expired-block" title="<?php echo __l($current_title); ?>"><?php echo $this->Html->link($this->Html->cInt($projectStatuses[ConstProjectStatus::FundingExpired],false).'<span>' .__l($current_title). '</span>', array('controller'=>'projects','action'=>'index', 'type' => 'myprojects','status'=>'expired'), array('escape' => false));?></span> </li>

	
		
        	
		
		</ul>
		</div>
		<table class="list">
			<tr>
				<th rowspan="2" class="actions"><?php echo __l('Actions');?></th>
				<th rowspan="2" class="dl">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Name'),'Project.name',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
				<th rowspan="2">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Collected Amount'),'collected_amount',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects'))).' ('.Configure::read('site.currency').')';?></div> / <div class="js-pagination"><?php echo $this->Paginator->sort(__l('Needed'),'needed_amount',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
				<?php if(Configure::read('Project.is_enable_threshold_limit')): ?>
					<th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Reserve amount'),'Project.reserve_amount',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects'))).' ('.Configure::read('site.currency').')';?></div></th>
				<?php endif; ?>
				<?php if( !empty($this->request->params['named']['status']) && ($this->request->params['named']['status'] == 'goal' || $this->request->params['named']['status'] == 'reserve_amount_reached')): ?>
				<th rowspan="2"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Received amount'),'Project.commission_amount',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects'))).' ('.Configure::read('site.currency').')';?></div></th>
				<?php endif; ?>
				<th rowspan="2">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Backers'), 'Project.project_fund_count',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
				<?php if( !empty($this->request->params['named']['status']) && ($this->request->params['named']['status'] == 'goal' || $this->request->params['named']['status'] == 'reserve_amount_reached')):
					$colspan = 3;
				else:
					$colspan = 2;
				endif;
				
				?>
				<th rowspan="2">
        <div >
        <?php echo __l('Funding Date'); ?>
		<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Start'), 'Project.project_funding_start_date',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>/<div class="js-pagination"><?php echo $this->Paginator->sort(__l('End'), 'Project.project_funding_end_date',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
        </div>
        </th>
				
				<?php 						 if(Configure::read('Project.is_project_comment_enabled') && !Configure::read('Project.is_fb_project_comment_enabled')):   ?>
				<th rowspan="2">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Comments'), 'Project.project_comment_count',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
				<?php endif; ?>
				<th rowspan="2">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Updates'), 'Project.blog_count',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
				<?php  if (Configure::read('Project.is_project_follower_enabled')): ?>
					<th rowspan="2">
						<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Followers'), 'Project.project_follower_count',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
					</th>
				<?php endif; ?>
				<th rowspan="2">
					<div class="js-pagination"><?php echo $this->Paginator->sort(__l('Messages'), 'Project.message_count',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div>
				</th>
			</tr>
			<tr>
    <?php if(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'reserve_amount_reached'): ?>
					<th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Reserve Amount Reached Date'), 'Project.reserve_reached_date',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div></th>
				<?php endif; ?>
				<?php if( !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'goal'): ?>
				<th><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Goal Reached Date'), 'Project.project_fund_goal_reached_date',array('url'=>array('controller'=>'projects','action'=>'index','type' => 'myprojects')));?></div></th>
				<?php endif; ?>

			</tr>
			<?php
			if (!empty($projects)):
				$i = 0;
				foreach ($projects as $project):
		?>
					<tr>
					<td class="actions dl">
					<?php
				
					?>
					<?PHP if($project['Project']['project_status_id'] != ConstProjectStatus::ProjectCancelled && $project['Project']['project_status_id'] != ConstProjectStatus::FundingExpired ): ?>
            <div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
									<?php 
										if (Configure::read('Project.listing_fee') and $project['Project']['project_status_id'] == ConstProjectStatus::Pending and empty($project['Transaction'])) :?>
										<li>	<?php
											echo $this->Html->link(__l('Pay listing fee'), array('controller' => 'payments', 'action'=>'project_pay_now', $project['Project']['id']), array('class' => 'pay js-edit', 'title' => __l('Pay listing fee')));?>
										</li>	<?php
										endif; 
									?>
								
									<?php 
										if($project['Project']['project_status_id'] == ConstProjectStatus::Pending || $project['Project']['project_status_id'] == ConstProjectStatus::OpenForIdea || ($project['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding && Configure::read('Project.is_allow_project_owner_to_edit_project_in_open_status'))): ?>
										<li>	<?php	echo $this->Html->link(__l('Edit'), array('controller' => 'projects', 'action' => 'edit', $project['Project']['id']), array('class' => 'edit js-edit', 'title' => __l('Edit'))); ?></li>
									<?php	endif;
									?>
								
									<?php 
										if (Configure::read('Project.is_allow_owner_project_cancel') and $project['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding) : ?>
										<li>	<?php
											echo $this->Html->link(__l('Cancel'), array('controller' => 'projects', 'action' => 'cancel', $project['Project']['id']), array('class' => 'edit js-delete cancel', 'title' => __l('Cancel'))); ?>
										</li>	<?php
										endif;
									?>
									<?php if( !empty($project['Project']['project_status_id']) && ($project['Project']['project_status_id'] == ConstProjectStatus::GoalReached || $project['Project']['project_status_id'] == ConstProjectStatus::FundingClosed ||$project['Project']['project_status_id'] ==  ConstProjectStatus::ReserveAmountReached)): ?>
										<li>	<?php
											echo $this->Html->link(__l('Manage Rewards'), array('controller'=>'project_funds','action'=>'index', 'project_id'=>$project['Project']['id'],'type'=>'manage'), array('class' => 'reward-link js-thickbox', 'title' => __l('Manage Rewards')));?>
										</li>	<?php
									endif;
									?>
				
					                   		 </ul>
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
              <?php endif; ?>
        </td>
						<td class="dl">
						<?PHP
                         if($is_wallet_enabled)
                         {
                            $project_status = $project['ProjectStatus']['name'];
                         }
                           else
                           {
                             $project_status = str_replace("Refunded","Voided",$project['ProjectStatus']['name']);
                           }
                        ?>
							<span class="project-status-info project-status-<?php echo $project['Project']['project_status_id']; ?>" title="<?php echo $this->Html->cText($project_status,false);?>">
								<?php echo $this->Html->cText($project['ProjectStatus']['name'],false);?>
							</span>
                           <?php echo $this->Html->link($this->Html->cText($project['Project']['name'],false) , array('controller'=>'projects' , 'action'=>'view' , $project['Project']['slug'] , 'admin'=>false) , array('class' => 'js-colorbox cboxelement', 'escape' => false,'title'=> $this->Html->cText($project['Project']['name'],false)));?>
                            <?php
								if(!empty($project['Project']['admin_suspend'])):
									echo '<span class="backeder round-5">'.__l('Admin Suspended').'</span>';
								else:
									if($project['Project']['is_system_flagged']):
										echo '<span class="active round-5">'.__l('System Flagged').'</span>';
									endif;
								endif; ?>
							
						</td>
						<td class="dr">
							<?php $collected_percentage = ($project['Project']['collected_percentage']) ? $project['Project']['collected_percentage'] : 0; ?>
							<div class="progress-block round-5">
								<p class="progress-bar progress-bar-amount round-5" title = '<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>'>
									<span class="round-5" style="width:<?php echo ($collected_percentage > 100) ? '100%' : $collected_percentage.'%'; ?>;" title = "<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>"><?php echo Configure::read('site.currency').$project['Project']['collected_amount'];?>
									</span>
								</p>
								<p><?php echo $this->Html->cCurrency($project['Project']['collected_amount']); ?> / <?php echo $this->Html->cCurrency($project['Project']['needed_amount']); ?>
									</p>
							</div>
						</td>
						<?php if(Configure::read('Project.is_enable_threshold_limit')): ?>
						<td class="dr"><?php echo $this->Html->cCurrency($project['Project']['reserve_amount']); ?></td>
						<?php endif; ?>
						<?php if( !empty($this->request->params['named']['status']) && ($this->request->params['named']['status'] == 'goal' || $this->request->params['named']['status'] == 'reserve_amount_reached')): ?>
							<td class="dr"><?php echo $this->Html->cCurrency($project['Project']['collected_amount'] - $project['Project']['commission_amount']); ?></td>
						<?php endif; ?>
						<td><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_fund_count'], false), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Backers', 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title' => $this->Html->cInt($project['Project']['project_fund_count'], false))); ?></td>
						<td>
		<?php if(empty($project['Project']['project_funding_start_date']) || $project['Project']['project_funding_start_date'] == '0000-00-00')   {
			echo '-';
		}  else {?>
			<div class="clearfix">
                       <div class="progress-block clearfix">
                       <?php
							$project_progress_precentage = 0;
							if(strtotime($project['Project']['project_funding_start_date']) < strtotime(date('Y-m-d H:i:s'))) {
								if($project['Project']['project_funding_end_date'] !== 	NULL) {
									$days_till_now = (strtotime(date("Y-m-d")) - strtotime(date($project['Project']['project_funding_start_date']))) / (60 * 60 * 24);
									$total_days = (strtotime(date($project['Project']['project_funding_end_date'])) - strtotime(date($project['Project']['project_funding_start_date']))) / (60 * 60 * 24);
                                     if($total_days)
                                     {
                                        $project_progress_precentage = round((($days_till_now/$total_days) * 100));
                                     }
                                     else{
                                        $project_progress_precentage = round((($days_till_now) * 100));
                                    }

									if($project_progress_precentage > 100)
									{
										$project_progress_precentage = 100;
									}
								} else {
									$project_progress_precentage = 100;
								}
							}
						?>
						<?php if($project['Project']['project_funding_end_date'])?>
                        <p class="progress-bar round-5">
                           <span class="round-5 <?php echo ($project['Project']['project_funding_end_date'] === NULL)? ' any-time-deal-progress': 'progress-status '; ?>" style="width:<?php echo $project_progress_precentage; ?>%" title="<?php echo ($project['Project']['project_funding_end_date'] === NULL)? __l(''): $project_progress_precentage.'%'; ?>">&nbsp;</span>
                        </p>
                        <p class="progress-value clearfix"><span class=""><?php echo $this->Html->cDateTimeHighlight($project['Project']['project_funding_start_date']);?></span>&nbsp;/&nbsp;<span class=""><?php echo (!is_null($project['Project']['project_funding_end_date']))? $this->Html->cDateTimeHighlight($project['Project']['project_funding_end_date']): ' - ';?></span></p>
                       </div>
                     </div>
					 <?php } ?>
                     </td>
						<?php if(Configure::read('Project.is_project_comment_enabled') && !Configure::read('Project.is_fb_project_comment_enabled')):  ?>
						<td><?php	
							echo $this->Html->link($this->Html->cInt($project['Project']['project_comment_count'], false), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Comments', 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title' => $this->Html->cInt($project['Project']['project_comment_count'], false)));
						?>
						</td>
						<?php endif; ?>
						<td><?php 
						if (!empty($project['Project']['feed_url']) && Configure::read('Project.is_enable_rss_feed')) {
							echo $this->Html->link($this->Html->cInt($project['Project']['project_feed_count'], false), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates', 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title'=> $this->Html->cInt($project['Project']['project_feed_count'], false)));
						} else {
							echo $this->Html->link($this->Html->cInt($project['Project']['blog_count'], false), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Updates', 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title' => $this->Html->cInt($project['Project']['blog_count'], false)));

						}
						
						?></td>
						<?php  if (Configure::read('Project.is_project_follower_enabled')): ?>
							<td><?php echo $this->Html->link($this->Html->cInt($project['Project']['project_follower_count'], false), array('controller' => 'projects', 'action' => 'view', $project['Project']['slug'], '#_Followers', 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title' => $this->Html->cInt($project['Project']['project_follower_count'], false)));?></td>
						<?php endif; ?>
						<td><?php echo $this->Html->link($this->Html->cInt(count($project['Message']), false),array('controller' => 'messages', 'action' => 'index', 'project_id' => $project['Project']['id'], 'admin' => false), array('class' => 'js-colorbox cboxelement', 'escape' => false, 'title' => $this->Html->cInt(count($project['Message']), false)));?></td>
					
						<?php if(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'myprojects' && !empty($this->request->params['named']['status']) &&	$this->request->params['named']['status'] == 'reserve_amount_reached'): ?>
							<td><?php echo ($project['Project']['reserve_reached_date'])?$this->Html->cDate($project['Project']['reserve_reached_date']):' ';?></td>
						<?php endif; ?>
						<?php if( !empty($this->request->params['named']['status']) && $this->request->params['named']['status'] == 'goal'): ?>
							<td><?php echo ($project['Project']['project_fund_goal_reached_date'])?$this->Html->cDate($project['Project']['project_fund_goal_reached_date']):' ';?></td>
						<?php endif; ?>
                    </tr>
		<?php
				endforeach;
			else:
		?>
				<tr><td colspan="22" class="notice"><?php echo __l('No Projects available');?></td></tr>
		<?php
			endif;
		?>
		</table>
		<div class="clearfix">
			<div class="paging js-pagination">
			<?php
				if (!empty($projects)) {
					echo $this->element('paging_links');
				}
			?>
			</div>
		</div>
	</div>
</div>